<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var beautySum = function (s) {
      let ans = 0;
      for (let i = 0; i < s.length; ++i) {
        const cnt = new Map();
        for (let j = i; j < s.length; ++j) {
          //对象是值的集合 ,所以可以进行判断。
          cnt.set(s[j], (cnt.get(s[j]) || 0) + 1);
          // 通过拥有 length 属性的对象或可迭代的对象来返回一个数组-
          const t = Array.from(cnt.values());
          ans += Math.max(...t) - Math.min(...t);
        }
      }
      return ans;
    };
    console.log(beautySum("aabcb"));

    var fn = (s) => {
      let snt = 0
      for (var i = 0; i < s.length; ++i) {
        let map = new Map()
        for (var j = i; j < s.length; ++j) {
          map.set(s[j], (map.get(s[j]) || 0) + 1)
          let t = Array.from(map.values())
          snt += Math.max(...t) - Math.min(...t)
        }
      }
      return snt
    }
    console.log(fn('aabcb'))
  </script>
</body>

</html>